import { TSMap } from "../cfw/struct/TSMap";
import { ConnectType } from "./NetConfig";

let FLAG = "$"
export default class ServiceInfo {

    //链接类型
    private connectType: string = ConnectType.WEB_SOCKET;

    //ip$port格式的唯一标识
    private serviceID: string = "";
    //用于验证链接合法性的字符串
    private token: string;
    //发送协议和返回协议的映射表，有些以协议发送和返回时相同的。
    //如果发送协议和返回协议号相同。这个表不用设置。
    protected protocolMap: TSMap<string, string> = new TSMap();

    constructor(cType: string, serviceID: string) {
        this.connectType = cType;
        this.serviceID = serviceID;
    }

    getConnectType() {
        return this.connectType;
    }

    getUrl() {
        if (this.serviceID.indexOf(FLAG) >= 0) {
            return this.serviceID.split(FLAG)[0];
        } else {
            return this.serviceID;
        }
    }

    getPort() {
        if (this.serviceID.indexOf(FLAG) >= 0) {
            return parseInt(this.serviceID.split(FLAG)[1]);
        } else {
            return 0;
        }
    }

    setToken(k: string) {
        this.token = k;
    }

    getToken() {
        return this.token;
    }

    setProtocolMap(map: TSMap<string, string>) {
        if (map) {
            this.protocolMap = map;
        }
    }

    getProtocalMap() {
        return this.protocolMap;
    }


}
